package com.gcb.controller.company;

import com.gcb.common.core.domain.PageResult;
import com.gcb.common.core.domain.R;
import com.gcb.controller.BaseController;
import com.gcb.domain.dto.GcbUserQueryDTO;
import com.gcb.domain.vo.CompanyUserVO;
import com.gcb.domain.vo.GcbUserVO;
import com.gcb.service.ICompanyUserService;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 工船宝企业用户关系Controller
 *
 * @author seh
 * @since 2024-03-08
 */
@RestController
@RequestMapping("/company/user")
public class CompanyUserController extends BaseController {
    @Autowired
    private ICompanyUserService companyUserService;

    @GetMapping("/list/by/userId")
    public R<List<CompanyUserVO>> getByUserId(@RequestParam Long userId) {
        List<CompanyUserVO> companyUserVOS = companyUserService.selectCompanyUserByUserId(userId);
        return R.ok(companyUserVOS);
    }

    @PostMapping("/page/by/companyId")
    public PageResult pageByCompanyId(@RequestBody GcbUserQueryDTO dto) {
        PageHelper.startPage(dto.getPageNum(), dto.getPageSize());
        List<CompanyUserVO> list = companyUserService.getMembersByCompanyId(Long.parseLong(dto.getCompanyId()));
        return PageResult.ok(list);
    }

    @PostMapping("/list/by/companyId/without/userId")
    public PageResult listByCompanyIdWithoutUserId(@RequestBody GcbUserQueryDTO dto) {
        long companyId = Long.parseLong(dto.getCompanyId());
        Long userId = dto.getUserId();
        List<CompanyUserVO> list = companyUserService.getMembersByCompanyIdWithoutUserId(companyId, userId);
        return PageResult.ok(list);
    }

}
